package com.cjd.common.recycler

import android.view.ViewPropertyAnimator
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.RecyclerView


/**
 * @Author chenjidong
 * @email 374122600@qq.com
 * created 2019/9/24
 * description 左边添加进入 右边退出删除
 */
class SlideItemAnimator : BaseItemAnimator() {

    override fun setRemoveAnimation(
        holder: RecyclerView.ViewHolder,
        animator: ViewPropertyAnimator
    ) {
        animator.translationX((holder.itemView.width).toFloat())
    }

    override fun removeAnimationEnd(holder: RecyclerView.ViewHolder) {

        holder.itemView.translationX = 0f
    }

    override fun addAnimationInit(holder: RecyclerView.ViewHolder) {

        holder.itemView.translationX = (-holder.itemView.width).toFloat()
    }

    override fun setAddAnimation(holder: RecyclerView.ViewHolder, animator: ViewPropertyAnimator) {
        animator.translationX(0f)
    }

    override fun addAnimationCancel(holder: RecyclerView.ViewHolder) {

        holder.itemView.translationX = 0f
    }

    override fun setOldChangeAnimation(
        holder: RecyclerView.ViewHolder,
        animator: ViewPropertyAnimator
    ) {
        animator.translationX((-holder.itemView.width).toFloat())
    }

    override fun oldChangeAnimationEnd(holder: RecyclerView.ViewHolder) {

        holder.itemView.translationX = 0f;
    }

    override fun newChangeAnimationInit(holder: RecyclerView.ViewHolder) {
        holder.itemView.translationX = holder.itemView.width.toFloat()
    }

    override fun setNewChangeAnimation(
        holder: RecyclerView.ViewHolder,
        animator: ViewPropertyAnimator
    ) {
        animator.translationX(0f)
    }

    override fun newChangeAnimationEnd(holder: RecyclerView.ViewHolder) {
        holder.itemView.translationX = 0f
    }
}